package com.quick.controller;

import com.quick.base.BaseTree;
import com.quick.base.Page;
import com.quick.base.Search;
import com.quick.service.ISysMenuService;
import com.quick.sys.domain.dto.SysMenuDTO;
import com.quick.sys.domain.pojo.SysMenu;
import com.quick.sys.domain.search.SysMenuSearch;
import com.quick.sys.domain.vo.MenuTreeVo;
import com.quick.sys.domain.vo.SysMenuVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/sys/menu")
@Api(tags ="系统菜单")
@AllArgsConstructor
public class SysMenuController {
    private final ISysMenuService sysMenuService;

    @ApiOperation("加载菜单树")
    @GetMapping("loadMenuTree")
    public List<MenuTreeVo> loadMenuTree(){
        return sysMenuService.loadMenuTree();
    }
    
    @ApiOperation("加载菜单树")
    @GetMapping("loadAdminMenuTree")
    public List<MenuTreeVo> loadAdminMenuTree(){
    	 return sysMenuService.loadAdminMenuTree();
    }

    @ApiOperation(value = "加载菜单",notes = "加载菜单")
    @PostMapping("loadMenu")
    public List<SysMenuVo> loadMenu(@RequestBody Search<SysMenu> search){
        return sysMenuService.loadAllMenu();
    }
    
    @ApiOperation(value = "加载菜单树V1",notes = "加载菜单树V1")
    @GetMapping("loadBaseTree")
    public List<BaseTree> loadBaseTree(){
		return sysMenuService.loadBaseTree();
    }
    
    @ApiOperation(value = "分页查询",notes = "分页查询")
    @PostMapping("search")
    public Page<SysMenuVo> search(@RequestBody Search<SysMenuSearch> search){
        return sysMenuService.searchMenu(search);
    }

    @ApiOperation(value = "保存菜单",notes = "保存菜单")
    @PostMapping("saveMenu")
    public Boolean saveMenu(@RequestBody SysMenuDTO sysMenu){
        return sysMenuService.saveOrUpdate(sysMenu);
    }

    @ApiOperation(value = "获取菜单",notes = "获取菜单")
    @GetMapping("getMenuById/{id}")
    public SysMenuVo getMenuById(@PathVariable("id") Integer id){
        return sysMenuService.getMenuById(id);
    }

    @ApiOperation(value = "删除菜单",notes = "删除菜单")
    @GetMapping("deleteMenu/{id}")
    public Boolean deleteMenu(@PathVariable("id") Integer id){
        return  sysMenuService.deleteMenu(id);
    }
}
